import java.util.Arrays;

public class Solution27 {
    public int removeElement(int[] nums, int val) {
        int j=0;
        for (int i=0;i<nums.length;i++){
            if (nums[i]!=val) {
                nums[j] = nums[i];
                j++;
            }
        }
        return j;
    }

    public static void main(String[] args) {
        int[] f=new int[]{0,1,2,2,3,0,4,2};
        System.out.println(new Solution27().removeElement(f,2));
        System.out.println(Arrays.toString(f));
    }
}
